<template>
	<view>
		<swiper class="swiper" :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
			:duration="duration" indicator-color="#ffff" :circular="true">
			<swiper-item v-for="(item, index) in swiperList">
				<image :src="item.image"></image>
			</swiper-item>
		</swiper>
		<view class="search-container">
			<u-search class="search-box" placeholder="请输入关键字" v-model="keyword" bg-color="#ffff"
				:show-action="false"></u-search>
		</view>
		<view>
			<u-waterfall v-model="flowList" ref="uWaterfall1">
				<template v-slot:left="{leftList}">
					<view class="demo-warter" v-for="(item, index) in leftList" :key="index">
						<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
						<u-lazy-load threshold="-450" border-radius="10" :image="item.image"
							:index="index"></u-lazy-load>
						<view class="demo-title">
							{{item.title}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view>
						<u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close"
							@click="remove(item.id)"></u-icon>
					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="demo-warter" v-for="(item, index) in rightList" :key="index">
						<u-lazy-load threshold="-450" border-radius="10" :image="item.image"
							:index="index"></u-lazy-load>
						<view class="demo-title">
							{{item.title}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view>
						<view class="demo-shop">
							{{item.shop}}
						</view>
						<u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close"
							@click="remove(item.id)"></u-icon>
					</view>
				</template>
			</u-waterfall>
			<u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus" @loadmore="addRandomData"></u-loadmore>
		</view>
	</view>
</template>

<script setup>
	// 选项式API vue2
	/* export default {
		data() {
			return {
				swiperList: [{
						image: "/static/33.jpeg"
					},
					{
						image: "/static/44.jpg"
					},
					{
						image: "/static/66.jpeg"
					}
				],
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500
			}
		},
		methods:{
			
		}
	} */
	// 组合式 API vue3/vue2
	import {
		ref
	} from 'vue';

	const swiperList = ref([{
			image: "/static/33.jpeg"
		},
		{
			image: "/static/44.jpg"
		},
		{
			image: "/static/66.jpeg"
		}
	])
	const indicatorDots = ref(true)
	const autoplay = ref(true)
	const interval = ref(2000)
	const duration = ref(500)

	const flowList = ref([{
			id: 1,
			price: 75,
			title: '手机',
			image: '/static/11.jpg',
		},
		{
			id: 2,
			price: 385,
			title: '笔记本电脑',
			image: '/static/22.jpeg',
		},
		{
			id: 3,
			price: 784,
			title: '耳机',
			image: '/static/33.jpeg',
		},
		{
			id: 4,
			price: 7891,
			title: '手表',
			image: '/static/44.jpg',
		},
		{
			id: 5,
			price: 2341,
			title: '养身壶',
			image: '/static/66.jpeg',
		},
		{
			id: 6,
			price: 2342,
			title: '手表',
			image: '/static/55.jpg',
		},
		{
			id: 7,
			price: 2341,
			title: '手机',
			image: '/static/11.jpg',
		},
		{
			id: 8,
			price: 2342,
			title: '电脑',
			image: '/static/22.jpeg',
		}
	])
	
	const uWaterfall1 = ref();
	const remove = ((id)=>{
		console.log(id);
		uWaterfall1.value.remove(id);
	})
</script>

<style lang="scss" scoped>
	.swiper {
		height: 240px;
	}

	.search-box {
		margin: 8px;
	}

	.search-container {
		background-color: #f7f7f7;
		position: sticky;
		top: 0;
		left: 0;
		z-index: 99;
	}

	.demo-warter {
		border-radius: 8px;
		margin: 5px;
		background-color: #ffffff;
		padding: 8px;
		position: relative;
	}

	.u-close {
		position: absolute;
		top: 32rpx;
		right: 32rpx;
	}

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}

	.demo-title {
		font-size: 30rpx;
		margin-top: 5px;
		color: $u-main-color;
	}

	.demo-tag {
		display: flex;
		margin-top: 5px;
	}

	.demo-tag-owner {
		background-color: $u-type-error;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 50rpx;
		font-size: 20rpx;
		line-height: 1;
	}

	.demo-tag-text {
		border: 1px solid $u-type-primary;
		color: $u-type-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}

	.demo-price {
		font-size: 30rpx;
		color: $u-type-error;
		margin-top: 5px;
	}

	.demo-shop {
		font-size: 22rpx;
		color: $u-tips-color;
		margin-top: 5px;
	}
</style>